#导入python string类自带的标点符号
from string import punctuation

#获取这些标点符号
dicts = {i: '' for i in punctuation}

# print(len(dicts))
# Python maketrans() 方法用于给 translate() 方法创建字符映射转换表
punc_table = str.maketrans(dicts)
# print(punc_table) 显示字符的映射都是空值

with open("Walden.txt") as fp:
    count = {}

    # 分割发现有字母和标点符号一组的
    list = fp.read().split()

    for line in list:

        # 用这个转换标点符号
        line = line.translate(punc_table)
        # 字典统计
        if line in count:
            count[line] += 1
        elif line == '':
            continue
        else:
            count[line] = 1
    # 排序
    count = sorted(count.items(), key=lambda item: item[1], reverse=True)
    for key, value in count:
        print(f"{key}   {value}")